package com.easyctrl.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.easyctrl.iface.FRMAdapterListener;
import com.easyctrl.ldy.domain.RoomBean;

public class RoomAdapter extends FRMAdapter<RoomBean> implements FRMAdapterListener{

	private static RoomAdapter instance; 
	private ArrayList<RoomBean> deletes;
	private RoomAdapter(Context context) { 
		super(context);
		deletes = new ArrayList<RoomBean>();
		setAdapterListener(this);
	}
	
	public ArrayList<RoomBean> getDeletes() {
		return deletes;
	}

	public static synchronized RoomAdapter getInstance(Context context){
		if(instance == null){
			instance = new RoomAdapter(context);
		}
		return instance;
	}
	@Override
	public void onGetView(com.easyctrl.adapter.FRMAdapter.ViewHolder holder,int position, ArrayList beans) {
		RoomBean bean = (RoomBean) beans.get(position);

		holder.name.setTag(bean);
		holder.delete.setTag(bean);

		holder.delete.setChecked(deletes.contains(bean));

		holder.name.setText(bean.name);
		holder.num.setText("" + (position + 1));
 
		if(bean.isUse == 1){ 
			holder.delete.setVisibility(View.GONE);
			holder.use.setVisibility(View.VISIBLE);
		}else{ 
			holder.delete.setVisibility(View.VISIBLE);
			holder.use.setVisibility(View.GONE);
		}
		
		holder.delete.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				RoomBean bean = (RoomBean)buttonView.getTag();
				if (isChecked) {
					deletes.add(bean);
				} else {
					deletes.remove(bean);
				}
			}
		});
	}
}
